package cn.wolfcode.service.Impl;

import cn.wolfcode.domain.MessageBoardHzh;
import cn.wolfcode.mapper.MessageBoardHzhMapper;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.IMessageBoardHzhService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class MessageBoardHzhServiceImpl implements IMessageBoardHzhService {

    @Autowired
    private MessageBoardHzhMapper messageBoardHzhMapper;


    @Override
    public void save(MessageBoardHzh messageBoardHzh) {
        messageBoardHzh.setCreateTimehzh(new Date());
        messageBoardHzh.setReplystatushzh(false);
        messageBoardHzhMapper.insert(messageBoardHzh);
    }

    @Override
    public void delete(Long id) {
        messageBoardHzhMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void update(MessageBoardHzh messageBoardHzh) {
        messageBoardHzhMapper.updateByPrimaryKey(messageBoardHzh);
    }

    @Override
    public MessageBoardHzh get(Long id) {
        return messageBoardHzhMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<MessageBoardHzh> listAll() {
        return messageBoardHzhMapper.selectAll();
    }

    @Override
    public PageInfo<MessageBoardHzh> query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize()); //对下一句sql进行自动分页
        List<MessageBoardHzh> messageBoardHzhs = messageBoardHzhMapper.selectForList(qo); //里面不需要自己写limit
        return new PageInfo<MessageBoardHzh>(messageBoardHzhs);
    }
}
